﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QuanLyDoanVien.General;
using QuanLyDoanVien.Bussiness;
using System.Data.SqlClient;
using System.Data;

namespace QuanLyDoanVien.DataLayer
{
    class BiThuChiDoanData
    {
        DataService m_BiThuChiDoanData = new DataService();

        public List<BiThuChiDoanInfo> layDSBiThu()
        {
            DataService.OpenConnection();
            List<BiThuChiDoanInfo> rs = new List<BiThuChiDoanInfo>();
            string sql = "select * from BiThu";
            SqlCommand command = new SqlCommand(sql);
            m_BiThuChiDoanData.Load(command);
            foreach (DataRow dr in m_BiThuChiDoanData.Rows)
            {
                BiThuChiDoanInfo btcd = new BiThuChiDoanInfo();
                btcd.MaHocSinh = dr["MaHocSinh"].ToString();
                btcd.HoTen = dr["HoTen"].ToString();
                btcd.MaLop = dr["MaLop"].ToString();
                btcd.NgaySinh = dr["NgaySinh"].ToString();
                btcd.GioiTinh = dr["GioiTinh"].ToString();
                btcd.DiemBiThu = float.Parse(dr["DiemBiThu"].ToString());
                btcd.NhanXet = dr["NhanXet"].ToString();
                btcd.TenLop = dr["TenLop"].ToString();
                btcd.TenChucVu = dr["TenChucVu"].ToString();
                btcd.HinhAnh = dr["AnhHocSinh"].ToString();
                rs.Add(btcd);
            }
            m_BiThuChiDoanData.CloseConnection();
            return rs;
        }

        public bool capNhatBiThu(string maHS, float diem, string nhanXet)
        {
            DataService.OpenConnection();
            SqlCommand cmd = new SqlCommand("UPDATE Tab_HocSinh SET DiemBiThu = @DiemBiThu, NhanXet = @NhanXet where MaHocSinh=@MaHocSinh ");
            cmd.Parameters.Add("MaHocSinh", SqlDbType.Char).Value = maHS;
          
            cmd.Parameters.Add("DiemBiThu", SqlDbType.Float).Value = diem;
            cmd.Parameters.Add("NhanXet", SqlDbType.NVarChar).Value = nhanXet;

            try
            {
                m_BiThuChiDoanData.ExecuteNoneQuery(cmd);
                m_BiThuChiDoanData.CloseConnection();
                return true;
            }
            catch (Exception ex)
            {
                m_BiThuChiDoanData.CloseConnection();
                return false;
            }
        }
    }
}
